package com.colin.springbootsource.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.core.annotation.Order;

/**
 * @author: Colin
 * 2019/12/22 15:55
 * @desc 第四种自定义系统监听器实现方式通过SmartApplicationListener接口,内部指定监听器感兴趣的事件,
 * 其他3种自定义实现方式是通过泛型指定,SpringBoot系统会通过该泛型去判断监听器对哪些事件感兴趣
 * @email zhaod@oceansoft.com.cn,colinzhaodong@gmail.com
 */
@Order(4)
@Slf4j
public class FourthListener implements SmartApplicationListener {
    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return ApplicationStartedEvent.class.isAssignableFrom(eventType) || ApplicationPreparedEvent.class.isAssignableFrom(eventType);
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        log.info("Fourth Listener");
    }
}
